home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2163 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  48 lines

  1. Path: news.bridge.net!news
  2. From: David Byrden <100101.2547@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Default template parameter..
  5. Date: 16 Jan 1996 06:02:19 GMT
  6. Organization: self-employed
  7. Message-ID: <4dff1b$ias@news.bridge.net>
  8. NNTP-Posting-Host: ppp-mia2-69.bridge.net
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  13.  
  14.  
  15. Can anyone clear up something about templates for me... here is a 
  16. simplified version of the STL class "set" showing one of its 
  17. constructors:
  18.  
  19. template <class Key, class Compare = less<Key> >
  20. class set
  21. {
  22.     set(const Compare& comp = Compare()) ;
  23.     ..........
  24.  
  25.  
  26. Now, obviously the comparing class will be less<int> when you instantiate 
  27. like this;
  28.  
  29.     set< int >  mySet () ;
  30.         
  31.  
  32. and of course you can set it to be something else in this manner;
  33.  
  34.     set< int, greater<int> >  mySet () ;
  35.  
  36. BUT: if I omit the Compare type from the template perameter list, 
  37. am I right in assuming the type will be deduced from the FUNCTION 
  38. parameter list of the constructor, i.e. the default type less<Key> will 
  39. be ignored??
  40.  
  41.     set< int >  mySet ( greater<int> ) ;
  42.  
  43. Thanks!
  44.  
  45.               David
  46.  
  47.  
  48.